home *** CD-ROM | disk | FTP | other *** search
/ C++ für Kids / C++ for kids.iso / Buch / Befund3a.cpp < prev    next >
C/C++ Source or Header  |  1998-12-27  |  2KB  |  73 lines

  1. //---------------------------------------------------------------------------
  2. #include <vcl\vcl.h>
  3. #pragma hdrstop
  4.  
  5. #include "Befund3a.h"
  6. //---------------------------------------------------------------------------
  7. #pragma resource "*.dfm"
  8.  
  9. const String DateiName = "Diagnose.txt";
  10. const String SammelName = "PsychoX.txt";
  11.  
  12. TForm1 *Form1;
  13. TStringList *Diagnose;
  14. TStringList *Psycho;
  15. int Nr;
  16.  
  17. //---------------------------------------------------------------------------
  18. __fastcall TForm1::TForm1(TComponent* Owner)
  19.     : TForm(Owner)
  20. {
  21. }
  22. //---------------------------------------------------------------------------
  23. void __fastcall TForm1::FormCreate(TObject *Sender)
  24. {
  25.   randomize ();
  26.   Diagnose = new TStringList;
  27.   Psycho = new TStringList;
  28.   try
  29.   {
  30.     Diagnose->LoadFromFile (DateiName);
  31.   }
  32.   catch (...)
  33.   {
  34.     Diagnose->Add ("Keine Sprechstunde");
  35.   }
  36.   ScrollBar1->Min = 0;
  37.   ScrollBar1->Max = Diagnose->Count - 1;
  38. }
  39. //---------------------------------------------------------------------------
  40. void __fastcall TForm1::Button1Click(TObject *Sender)
  41. {
  42.   Panel1->Caption = "";
  43.   Edit1->Text = "";
  44.   Edit1->SetFocus ();
  45. }
  46. //---------------------------------------------------------------------------
  47. void __fastcall TForm1::Button2Click(TObject *Sender)
  48. {
  49.   Psycho->Add (Edit1->Text);
  50.   Nr = random (Diagnose->Count);
  51.   Panel1->Caption = Diagnose->Strings[Nr];
  52.   Psycho->Add (Panel1->Caption);
  53. }
  54. //---------------------------------------------------------------------------
  55. void __fastcall TForm1::ScrollBar1Change(TObject *Sender)
  56. {
  57.   Panel1->Caption = Diagnose->Strings[ScrollBar1->Position];
  58. }
  59. //---------------------------------------------------------------------------
  60. void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
  61. {
  62.   try
  63.   {
  64.     Psycho->SaveToFile (SammelName);
  65.   }
  66.   catch (...)
  67.   {
  68.     Application->MessageBox
  69.       ("Fehler beim Speichern der Datei!", "Achtung!", 0+48);
  70.   }
  71. }
  72. //---------------------------------------------------------------------------
  73.